<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return['status']=$this->order_status;
$return['buytype']=$this->buy_types;
$return['sendtype']=$this->send_types;
$return['paytype']=get_pay_types();
$return['paytype']['peerpay']='找人代付';
$return['ispay']=array('0'=>'未支付','1'=>'已支付');
if($_RQ['op']=='get'){
	$status=isset($_RQ['status'])?$_RQ['status']:1;
	$return['params']=array('status'=>$status);
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
    $orderby='id desc';
	$total='';
	if(!empty($_RQ['ordersn'])){
		$params['ordersn']=trim($_RQ['ordersn']);
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	if(!empty($_RQ['plugin_name'])){
		$params['plugin_name']=trim($_RQ['plugin_name']);
		$return['params']['plugin_name']=$_RQ['plugin_name'];
	}
	if(isset($_RQ['status']) && $_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(isset($_RQ['sendtype'])){
		$params['sendtype']=intval($_RQ['sendtype']);
		$return['params']['sendtype']=$_RQ['sendtype'];
	}
	if(isset($_RQ['buytype'])){
		$params['buytype']=intval($_RQ['buytype']);
		$return['params']['buytype']=$_RQ['buytype'];
	}
	$return['list']=$this->getslice('server_order',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$item){
			$user=model('core/member')->detail($item['mid'],array('nickname','mobile'));
			$item['worker_name']=pdo_getcolumn('jy_meye_store_worker',array('id'=>$item['worker_id'],'uniacid'=>$_SESSION['uniacid']),'name');
			$item['serve']=pdo_get('jy_meye_serve',array('id'=>$item['serve_id'],'uniacid'=>$_SESSION['uniacid']),array('title','serve_time','image'));
			$item['username']=$user['nickname'];
			$item['user_mobile']=$user['mobile'];
			$package=json_decode($item['package'],true);
			$item['package']=$package['package_title'];
			$serve_times=$item['serve']['serve_time'];
			$serve_times=json_decode($serve_times,true);
			$item['serve_time']=$item['day'].'--'.$serve_times[$item['timeid']]['times']['start'].'-'.$serve_times[$item['timeid']]['times']['end'];
			$item['createtime']=date('Y-m-d H:m:s',$item['createtime']);
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='upprice'){
	$id=intval($_RQ['id']);
	$post=get_postdata();	
	if($post['price']){
		if(!is_numeric($post['price'])){
			exi('价格必须是数字！','error');
		}
		if(!method_exists(cfc('pay'),'change_pay_fee')){
			exi('修改价格失败！请联系管理员，更新框架到最新','error');
		}
		$price=floatval($post['price']);
		if ($price < 0) 
		{
			$price = 0;
		}
		$this->model('order')->upprice($post['id'],$price);
		exi('改价成功！','','jy_weishop/manage.order/');	
	}
	$item=$this->get('order',array('id'=>$id),array('id','price'));
	$htmls=array(
		'type'=>'edit',
		'desc'=>'修改价格',
	);
	$htmls['edit']=array(
		array('type'=>'string','title'=>'价格','name'=>'price','help'=>'修改价格！'),	
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
?>